<!DOCTYPE html>
<html lang="zh_CN" xmlns:th="http://www.thymeleaf.org"
				xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
	<head>
		<meta charset="utf-8" />
		<title>修改密码</title>
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />

		<link href="css/bootstrap.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="css/font-awesome.min.css" />
		<link rel="stylesheet" href="css/ace.min.css" />
		<link rel="stylesheet" href="css/ace-rtl.min.css" />
		<link rel="stylesheet" href="css/layui.css" media="all"/>
		<link rel="stylesheet" href="css/layui.css" media="all"/>
		<script src='js/jquery-2.0.3.min.js'></script>
		<script src="/layui.js"></script>
		<script>
		    var layer;
		    var $;
		    layui.use(['layer'], function () {
		    	$ = layui.jquery, layer = layui.layer;
		    })
		</script>
		<script type="text/javascript">
		//点击修改
		function submitReset(){
			var email=$('#reg_email').val();
			var token=$('#token').val();
			var password=$('#reg_password').val();
			var repassword=$('#reg_repassword').val();
			var re = /^[a-zA-Z0-9]([a-zA-Z0-9]*[-_.]?[a-zA-Z0-9]+)+@([a-zA-Z0-9]+\.)+[a-zA-Z]{2,}$/;
			var passwordTest = /^[a-zA-Z0-9._]{6,16}$/;
			if(email==""||!re.test(email)||token==""){
				layer.msg("非法操作，邮箱或者令牌不能空");
				return ;
			}
			if(password==""){
				layer.msg("请设置密码！");
				return ;
			}
			if(!passwordTest.test(password))
		    {
		        layer.msg("密码必须由6-16位字符组成!");
		        return ;
		    }
			if(password!=repassword){
			    layer.msg("两次密码不一致!");
			    return ;
			}
			$("#regSubmit").attr("disabled","disabled");
			$.post("/submitResetPwd",{
				email:email,
				token:token,
				password:password
	         },function(data,status){
	        	 if(data=="true"){
	        		 layer.open({
	        		        type: 1,
	        		        title: "提示信息",
	        		        closeBtn: false,
	        		        area: '280px',
	        		        btn: ['确认'],
	        		        moveType: 1, //拖拽模式，0或者1
	        		        content: '<div style="padding:15px 20px; text-align:justify; line-height: 22px; text-indent:2em;border-bottom:1px solid #e2e2e2;"><p>修改密码成功,请登录</p></div>',
	        		        success: function(layero){
	        		        	var btn = layero.find('.layui-layer-btn');
	        					btn.css('text-align', 'center');
	        					btn.on("click",function(){
	        						location.href="../login";
	        					})
	        		        }
	        		    });
	        	 }else if(data=="false"){
	        		 layer.msg("修改密码失败");
	        		 $('#regSubmit').removeAttr("disabled");
	        	 }else{
	        		 layer.msg(data);
	        	 }
	         });
		}
		
		function goIndex(){
			location.href="../";
		}
		</script>
	</head>

	<body class="login-layout">
		<div class="main-container">
			<div class="main-content">
				<div class="row">
					<div class="col-sm-10 col-sm-offset-1">
						<div class="login-container">
							<div class="center" onclick="goIndex()">
								<h1>
									<i class="icon-leaf green"></i>
									<span class="red">慈善</span>
									<span class="white">图书系统</span>
								</h1>
								<h4 class="blue">&copy; Charity Book</h4>
							</div>

							<div class="space-6"></div>

							<div class="position-relative">
								<div id="signup-box" class="signup-box widget-box no-border visible">
									<div class="widget-body">
										<div class="widget-main">
											<h4 class="header green lighter bigger">
												<i class="icon-group blue"></i>
												修改密码
											</h4>

											<div class="space-6"></div>
											<p> 请输入您的信息: </p>

											<form  id="regForm">
												<fieldset>
													<label class="block clearfix">
														<span class="block input-icon input-icon-right">
															<input type="hidden" id="token" readonly="readonly" th:value="${token}"/>
															<input type="email" class="form-control" placeholder="邮箱" name="email" id="reg_email" readonly="readonly" th:value="${email}"/>
															<i class="icon-envelope"></i>
														</span>
													</label>
													
													<label class="block clearfix">
														<span class="block input-icon input-icon-right">
															<input type="password" class="form-control" placeholder="密码" name="password" id="reg_password"/>
															<i class="icon-lock"></i>
														</span>
													</label>

													<label class="block clearfix">
														<span class="block input-icon input-icon-right">
															<input type="password" class="form-control" placeholder="再次输入密码" id="reg_repassword"/>
															<i class="icon-retweet"></i>
														</span>
													</label>

													<div class="clearfix">
														<button id="regSubmit" type="button" class="width-65 pull-right btn btn-sm btn-success" onclick="submitReset()">
															确认修改
															<i class="icon-arrow-right icon-on-right"></i>
														</button>
													</div>
												</fieldset>
											</form>
										</div>
									</div><!-- /widget-body -->
								</div><!-- /signup-box -->
							</div><!-- /position-relative -->
						</div>
					</div><!-- /.col -->
				</div><!-- /.row -->
			</div>
		</div><!-- /.main-container -->


		
		<script src='js/jquery.mobile.custom.min.js'></script>
		<script type="text/javascript">
			function show_box(id) {
			 jQuery('.widget-box.visible').removeClass('visible');
			 jQuery('#'+id).addClass('visible');
			}
		</script>
		<script src="http://cdn.bootcss.com/jquery/1.11.0/jquery.min.js" type="text/javascript"></script>
</body>
</html>
